package API_Jung;


import edu.uci.ics.jung.visualization.VisualizationViewer;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.Point2D;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import metodologia.TestNode;

public class MyMouseMenus {
    
    public static class EdgeMenu extends JPopupMenu implements java.io.Serializable{        
        // private JFrame frame; 
        public EdgeMenu() {
            super("Edge Menu");
            // this.frame = frame;
            //this.add(new DeleteEdgeMenuItem<String>());
        }
        
    }
    
    public static class VertexMenu extends JPopupMenu {
        public VertexMenu() {
            super("Vertex Menu");
            //this.add(new DadosMenuItem("Dados do teste")); //NÃO PRECISA
            this.add(new ListEtapasItem("Lista de Etapas"));
            //this.addSeparator();
            //this.add(new DeleteVertexMenuItem<TestNode>());
            
            
        }
    }

    public static class ListEtapasItem extends JMenuItem implements VertexMenuListener<TestNode>, MenuPointListener {
        TestNode vertex;
        VisualizationViewer visComp;
        Point2D point;


    @Override
    public void setVertexAndView(TestNode vertex, VisualizationViewer visComp) {
        this.vertex = vertex;
        this.visComp = visComp;
    }

    @Override
    public void setPoint(Point2D point) {
        this.point = point;
    }

    public  ListEtapasItem(String titulo) {            
        super(titulo);
        this.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {

                Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
                // Determine the new location of the window
                int w = vertex.getToDoScreen().getSize().width;
                int h = vertex.getToDoScreen().getSize().height;
                int x = (dim.width-w)/2;
                int y = (dim.height-h)/2;

                // Move the window
                if (vertex.getState() == 1 || vertex.getState() == 3) {
                    if (vertex.getType() == 2) {
                        vertex.getToDoScreen().setLocation(x, y);
                        vertex.getToDoScreen().setVisible(true); 
                    }
                }
            }

        });
    }


    }

    public static class DadosMenuItem extends JMenuItem implements VertexMenuListener<TestNode>, MenuPointListener{
        TestNode vertex;
        VisualizationViewer visComp;
        Point2D point;
         
         
        @Override
        public void setVertexAndView(TestNode vertex, VisualizationViewer visComp) {
            this.vertex = vertex;
            this.visComp = visComp;
        }

        @Override
        public void setPoint(Point2D point) {
            this.point = point;
        }
        
        public  DadosMenuItem(String titulo) {            
            super(titulo);
            this.addActionListener(new ActionListener() {
            @Override
                public void actionPerformed(ActionEvent e) {

                    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
                    // Determine the new location of the window
                    int w = vertex.getToDoScreen().getSize().width;
                    int h = vertex.getToDoScreen().getSize().height;
                    int x = (dim.width-w)/2;
                    int y = (dim.height-h)/2;

                    // Move the window
                    if (vertex.getType() == 2) {
                        vertex.getJFData().setLocation(x, y);
                        vertex.getJFData().setVisible(true);
                    }
                }

            });
                
        }
     
     }
        
}
    

